﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AwesomeGame
{
    public class Common
    {
        public static bool RectanglesIntersect(Rectangle r1, Rectangle r2)
        {
            List<Vector2> r1points = GetPointsOfRectangle(r1);

            foreach (Vector2 point in r1points)
                if (IsPointInRectangle(point, r2))
                    return true;

            List<Vector2> r2points = GetPointsOfRectangle(r2);

            foreach (Vector2 point in r2points)
                if (IsPointInRectangle(point, r1))
                    return true;

            return false;
        }

        public static int GetRandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

        public static List<Vector2> GetPointsOfRectangle(Rectangle rectangle)
        {
            List<Vector2> points = new List<Vector2>();
            points.Add(new Vector2(rectangle.X, rectangle.Y));
            points.Add(new Vector2(rectangle.X, rectangle.Y + rectangle.Height));
            points.Add(new Vector2(rectangle.X + rectangle.Width, rectangle.Y));
            points.Add(new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height));

            return points;
        }

        public static bool IsPointInRectangle(Vector2 point, Rectangle rectangle)
        {
            if (point.X >= rectangle.X && point.X <= rectangle.X + rectangle.Width)
                if (point.Y >= rectangle.Y && point.Y <= rectangle.Y + rectangle.Height)
                    return true;
            return false;
        }
    }
}
